﻿using Nop.Core;
using Nop.Core.Caching;
using Nop.Core.Data;
using Nop.Core.Domain.WindAlert;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Nop.Services.WindAlert
{
    /// <summary>
    /// Station service
    /// </summary>
    //public partial class StationService : IStationService
    //{
    //    #region Constants
    //    private const string STATIONS_ALL_KEY = "Nop.station.all-{0}";
    //    private const string STATIONS_BY_ID_KEY = "Nop.station.id-{0}";
    //    private const string STATIONS_PATTERN_KEY = "Nop.station.";
    //    #endregion

    //    #region Fields

    //    private readonly IRepository<Station> _stationRepository;
    //    private readonly ICacheManager _cacheManager;
    //    #endregion

    //    #region Ctor

    //    /// <summary>
    //    /// Ctor
    //    /// </summary>
    //    /// <param name="cacheManager">Cache manager</param>
    //    /// <param name="stationRepository">Live Station repository</param>
    //    public StationService(ICacheManager cacheManager,
    //        IRepository<Station> stationRepository)
    //    {
    //        this._cacheManager = cacheManager;
    //        this._stationRepository = stationRepository;
    //    }
    //    #endregion

    //    #region Methods

    //    /// <summary>
    //    /// Deletes a station
    //    /// </summary>
    //    /// <param name="station">Station</param>
    //    public virtual void DeleteStation(Station station)
    //    {
    //        if (station == null)
    //            throw new ArgumentNullException("station");

    //        station.Deleted = true;
    //        UpdateStation(station);
    //    }

    //    /// <summary>
    //    /// Gets all stations
    //    /// </summary>
    //    /// <param name="showHidden">A value indicating whether to show hidden records</param>
    //    /// <param name="stationId">Station Id</param>
    //    /// <returns>Station collection</returns>
    //    public virtual IList<Station> GetAllStations(bool showHidden = false)
    //    {
    //        string key = string.Format(STATIONS_ALL_KEY, showHidden);
    //        return _cacheManager.Get(key, () =>
    //        {
    //            var query = from m in _stationRepository.Table
    //                        orderby m.DisplayOrder
    //                        where (showHidden || m.Published) &&
    //                        !m.Deleted 
    //                        select m;
    //            var stations = query.ToList();
    //            return stations;
    //        });
    //    }

    //    /// <summary>
    //    /// Gets all stations with metar bool
    //    /// </summary>
    //    /// <param name="showHidden">A value indicating whether to show hidden records</param>
    //    /// <param name="stationId">Station Id</param>
    //    /// <returns>Station collection</returns>
    //    public virtual IList<Station> GetAllStations(bool isMetar, bool showHidden = false)
    //    {
    //        string key = string.Format(STATIONS_ALL_KEY, showHidden);
    //        return _cacheManager.Get(key, () =>
    //        {
    //            var query = from m in _stationRepository.Table
    //                        orderby m.DisplayOrder
    //                        where (showHidden || m.Published) &&
    //                        !m.Deleted &&
    //                        m.IsMetar == isMetar
    //                        select m;
    //            var stations = query.ToList();
    //            return stations;
    //        }); 
    //    }

    //    /// <summary>
    //    /// Gets all stations
    //    /// </summary>
    //    /// <param name="pageIndex">Page index</param>
    //    /// <param name="pageSize">Page size</param>
    //    /// <param name="showHidden">A value indicating whether to show hidden records</param>
    //    /// <param name="stationId">Station Id</param>
    //    /// <returns>Stations</returns>
    //    public virtual IPagedList<Station> GetAllStations(int pageIndex, int pageSize, bool showHidden = false)
    //    {
    //        var stations = GetAllStations(showHidden);
    //        return new PagedList<Station>(stations, pageIndex, pageSize);
    //    }

    //    /// <summary>
    //    /// Gets all stations
    //    /// </summary>
    //    /// <param name="pageIndex">Page index</param>
    //    /// <param name="pageSize">Page size</param>
    //    /// <param name="showHidden">A value indicating whether to show hidden records</param>
    //    /// <param name="stationId">Station Id</param>
    //    /// <returns>Stations</returns>
    //    public virtual IPagedList<Station> GetAllStations(int pageIndex, int pageSize,bool isMetar, bool showHidden = false)
    //    {
    //        var stations = GetAllStations(isMetar, showHidden);
    //        return new PagedList<Station>(stations, pageIndex, pageSize);
    //    }

    //    /// <summary>
    //    /// Gets a station
    //    /// </summary>
    //    /// <param name="stationId">Station identifier</param>
    //    /// <returns>Station</returns>
    //    public virtual Station GetStationById(int stationId)
    //    {
    //        if (stationId == 0)
    //            return null;

    //        string key = string.Format(STATIONS_BY_ID_KEY, stationId);
    //        return _cacheManager.Get(key, () =>
    //        {
    //            var station = _stationRepository.GetById(stationId);
    //            return station;
    //        });
    //    }

    //    /// <summary>
    //    /// Inserts a station
    //    /// </summary>
    //    /// <param name="station">Station</param>
    //    public virtual void InsertStation(Station station)
    //    {
    //        if (station == null)
    //            throw new ArgumentNullException("station");

    //        _stationRepository.Insert(station);

    //        //cache
    //        _cacheManager.RemoveByPattern(STATIONS_PATTERN_KEY);
    //    }

    //    /// <summary>
    //    /// Updates the station
    //    /// </summary>
    //    /// <param name="station">Station</param>
    //    public virtual void UpdateStation(Station station)
    //    {
    //        if (station == null)
    //            throw new ArgumentNullException("station");

    //        _stationRepository.Update(station);

    //        //cache
    //        _cacheManager.RemoveByPattern(STATIONS_PATTERN_KEY);
    //    }



    //    #endregion

    //}
}
